<%@page import="net.vinote.smart.platform.service.servlet.FileUploadServlet"%>
<%@page import="net.vinote.smart.platform.service.bean.DataWindowCatalog"%>
<%@page import="java.io.FileFilter"%>
<%@page import="java.io.File"%>
<%@page import="net.vinote.smart.platform.comm.StringFunction"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@include file="/comm/begin.jsp"%>
<%
	session.setAttribute("returnURL", basePath+request.getServletPath()+"?"+request.getQueryString());
	Object result=session.getAttribute("result");
	int r=0;
	if(result!=null){
		r=Integer.valueOf(result.toString());		
		session.removeAttribute("result");
	}
	String imgPath=request.getParameter("path");
	String doNo=request.getParameter("doNo");
	DataWindowCatalog catalog= SRE.getDataWindowCatalog(doNo);
	if(imgPath==null){
		imgPath=StringFunction.nullToBlank(session.getAttribute("path"));
		session.removeAttribute("path");
	}
%>
<style>
#historyImg img {
	height: 60px;
	width: 60px
}
</style>
<form action="fileUpload<%="?"+request.getQueryString() %>" method="post" enctype="multipart/form-data">
	<input type="file" name="file" /><input type="submit"
		value="${msg.upload}" />
</form>

<!-- 历史图片 -->
<div id="historyImg">
	<%
	String savePath = session.getServletContext().getRealPath("/")
				+ "WEB-INF" + File.separator + "attache"
				+ File.separator + CurUser.getUserID();
	if(catalog!=null){
		savePath+=File.separator+catalog.getMainTable().toLowerCase();
	}
	File saveDir=new File(savePath);
	if(saveDir.isDirectory()){
		FileFilter imgFilter=new FileFilter(){
			 public boolean accept(File pathname){
				 return pathname.isFile()&&pathname.getName().endsWith(".jpg");
			 }
		};
		for(File f:saveDir.listFiles(imgFilter)){
			%>
	<img src="attache/<%=f.getName()%><%=(doNo==null)?"":"?doNo="+doNo %>" />
	<%
		}
	}
%>
</div>
<img id="curImg" name='img' src="<%=imgPath%>" />
<%
	if(FileUploadServlet.SUCCESS==r){
%>
上传成功!
<%}else if(FileUploadServlet.ERROR==r){ %>
上传失败!
<%} %>
<script type="text/javascript">
<!--
$("#historyImg img").click(function(){
	$("#curImg").attr('src',$(this).attr('src'));
});
//-->
</script>
<%@include file="/comm/end.jsp"%>